package com.itheima.controller;

import com.itheima.domain.ClassQueryParam;
import com.itheima.domain.PageResult;
import com.itheima.domain.Result;
import com.itheima.domain.pojo.Clazz;
import com.itheima.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/clazzs")
@RestController
public class ClassController {

    @Autowired
    private ClassService classService;

    /**
     * 所有班级查询
     * @return
     */
    @GetMapping("/list")
    public Result getAll() {
        List<Clazz> clazzs =classService.getAll();
        System.out.println(22222);
        System.out.println(11111);
        return Result.success(clazzs);
    }

    /**
     * 新增班级
     */
    @PostMapping
    public Result insertClass(@RequestBody Clazz clazz){
        classService.insertClass(clazz);
        return Result.success();
    }

    /**
     * 删除班级
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable  Integer id){
        classService.deleteById(id);
        return Result.success();
    }

    /**
     * 根据id查询班级
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        Clazz clazz=classService.getById(id);
        return Result.success(clazz);
    }

    /**
     * 修改班级
     */
    @PutMapping
    public Result updateById(@RequestBody Clazz clazz){
        classService.updateById(clazz);
        return Result.success();
    }

    /**
     * 班级列表查询
     */
    @GetMapping
    public Result getList(ClassQueryParam c){
        PageResult<Clazz> list = classService.getList(c);
        return Result.success(list);

    }
}
